
CPP = g++
AR = ar
CP = cp
RM = rm

ifeq ($(DEBUG), no)
 CPP_FLAGS = -Wall -O2
endif

ifeq ($(DEBUG), yes)
 CPP_FLAGS = -Wall -g
endif

DEF_OUTDIR = bin
LIB_TARGET = 2Desa

ifeq ($(BUILD), windows)
 LUA_INCLUDE = $(DIR_PREFIX)/../lua-5.1.4/src
 LUA_LIBS = $(DIR_PREFIX)/../lua-5.1.4/src
 LUA_LIB = lua51.dll
 SDL_INCLUDE = $(DIR_PREFIX)/../SDL-1.2.12/include
 SDL_LIBS = $(DIR_PREFIX)/../SDL-1.1.12/lib
 LIB_EXT = dll
 IMP_LIB_CORE = -Wl,--out-implib,$(DIR_PREFIX)/bin/lib$(LIB_TARGET).$(LIB_EXT).a
 IMP_LIB_LUA = -Wl,--out-implib,$(DIR_PREFIX)/bin/lib$(LIB_TARGET)_lua.$(LIB_EXT).a
endif

ifeq ($(BUILD), linux)
 LUA_INCLUDE = /usr/local/include
 LUA_LIBS = /usr/local/lib
 LUA_LIB = lua
 SDL_INCLUDE = /usr/include
 SDL_LIBS = /usr/lib
 LIB_EXT = so
 IMP_LIB_CORE =
 IMP_LIB_LUA =
endif

DIR_PREFIX ?= .

HEADERS_CORE = $(filter %.hpp, $(shell ls -1 $(DIR_PREFIX)/include/Core | grep -E "*\.hpp"))
HEADERS = $(foreach hdr_file, $(HEADERS_CORE), $(DIR_PREFIX)/include/Core/$(hdr_file))

HEADERS_EXT = $(filter %.hpp, $(shell ls -1 $(DIR_PREFIX)/include/Ext | grep -E "*\.hpp"))
HEADERS += $(foreach hdr_file, $(HEADERS_EXT), $(DIR_PREFIX)/include/Ext/$(hdr_file))

HEADERS_SDL = $(filter %.hpp, $(shell ls -1 $(DIR_PREFIX)/include/SDL | grep -E "*\.hpp"))
HEADERS += $(foreach hdr_file, $(HEADERS_SDL), $(DIR_PREFIX)/include/SDL/$(hdr_file))

HEADERS_LUA = $(filter %.hpp, $(shell ls -1 $(DIR_PREFIX)/include/Lua | grep -E "*\.hpp"))
HEADERS += $(foreach hdr_file, $(HEADERS_LUA), $(DIR_PREFIX)/include/Lua/$(hdr_file))

%.po: %.cpp $(HEADERS)
	@echo " CC" $@
	$(CPP) $(CU_CPP_FLAGS) -c $(CU_INCLUDE) -o $@ $<
